package com.example.testcalendaractivity.util;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.style.ForegroundColorSpan;

import androidx.core.content.ContextCompat;

import com.example.testcalendaractivity.R;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;

public class TodayColorDecorator implements DayViewDecorator {
    private final Drawable selectedBackground;  // 选中日期的背景
    private final Drawable todayBackground;     // 今日日期的背景
    private final CalendarDay today;            // 今日日期


    public TodayColorDecorator(Context context) {
        // 设置选中日期的背景
        selectedBackground = ContextCompat.getDrawable(context, R.drawable.selected_background);
        // 设置今日日期的背景
        todayBackground = ContextCompat.getDrawable(context, R.drawable.today_background);
        // 获取今天的日期
        today = CalendarDay.today();
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return day.equals(today);
    }

    @Override
    public void decorate(DayViewFacade view) {
        /// 如果当前日期是选中的日期，设置选中背景和字体颜色

        view.setSelectionDrawable(selectedBackground);     // 选中日期的背景
        view.addSpan(new ForegroundColorSpan(Color.WHITE)); //
        // 如果选中日期不是今天，设置今日的背景色
        view.setBackgroundDrawable(todayBackground);  // 今日的背景色


    }
}
